/*******************************************************************************
 * Copyright (c) 2009-2011 ETCORE Labs. All rights reserved. 
 * 
 * This software is the confidential and proprietary information of ETCORE Labs.
 * You shall not disclose such confidential information and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with ETCORE Labs. 
 * 
 * Support can be obtained from support forums at:  http://www.etcore.com/
 * /
 *******************************************************************************/
package etcore.webapp.grouptalk.common.service;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import etcore.webapp.grouptalk.common.dao.BaseDAO;
import etcore.webapp.grouptalk.common.dao.HibernateSessionFactory;
import etcore.webapp.grouptalk.common.dao.TagContainerDAO;
import etcore.webapp.grouptalk.common.object.TagContainer;

/**
 * TagContainerService implements queries and transactions on TagContainer
 * 
 * @author ETCORE GroupTalk Developers
 * 
 */
public class TagContainerService extends BaseService {

	@Override
	public void deleteSingle(Object persistentInstance) {
		Session session = HibernateSessionFactory.getSession();
		Transaction tx = session.beginTransaction();
		try {

			BaseDAO dao = new TagContainerDAO();
			dao.deleteSingle(persistentInstance);
			tx.commit();

		} catch (RuntimeException re) {
re.printStackTrace();
			tx.rollback();
		} finally {
			if (session != null)
				session.close();
		}

	}

	public TagContainer findById(java.lang.Integer id) {

		Session session = HibernateSessionFactory.getSession();
		try {
			TagContainerDAO dao = new TagContainerDAO();
			TagContainer result = dao.findById(id);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public Integer findGroupId(java.lang.Integer id) {
		Session session = HibernateSessionFactory.getSession();
		try {
			TagContainerDAO dao = new TagContainerDAO();
			Integer result = dao.findGroupId(id);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<TagContainer> findByProperty(String propertyName, Object value,
			int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			TagContainerDAO dao = new TagContainerDAO();
			List<TagContainer> result = dao.findByProperty(propertyName, value,
					begin, length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<TagContainer> findByProperty(String propertyName, Object value) {

		Session session = HibernateSessionFactory.getSession();
		try {
			TagContainerDAO dao = new TagContainerDAO();
			List<TagContainer> result = dao.findByProperty(propertyName, value);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeByProperty(String propertyName, Object value) {

		Session session = HibernateSessionFactory.getSession();
		try {
			TagContainerDAO dao = new TagContainerDAO();
			long result = dao.findSizeByProperty(propertyName, value);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<TagContainer> findBy2Properties(String propertyName1,
			Object value1, String propertyName2, Object value2) {

		Session session = HibernateSessionFactory.getSession();
		try {
			TagContainerDAO dao = new TagContainerDAO();
			List<TagContainer> result = dao.findBy2Properties(propertyName1,
					value1, propertyName2, value2);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<TagContainer> findAll(int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			TagContainerDAO dao = new TagContainerDAO();
			List<TagContainer> result = dao.findAll(begin, length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

}